package com.gc.controller.teacherServlet;


import com.gc.entity.Check;
import com.gc.service.CheckService;
import com.gc.service.impl.CheckServiceImpl;
import com.gc.util.result.R;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Timestamp;

@WebServlet(name = "TeacherCheckAdd", value = "/TeacherCheckAdd")
public class TeacherCheckAdd extends HttpServlet {
    CheckService checkservice = new CheckServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    /**
     *     Long id;
     *     String checkid;
     *     String bookid;
     *     String cid;
     *     String stage;
     *     Timestamp starttime;
     *     Timestamp endtime;
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Gson gson = new Gson();

        Check check = new Check(
                null,
                request.getParameter("checkid"),
                request.getParameter("bookid"),
                request.getParameter("cid"),
                Integer.valueOf(request.getParameter("stage")),
                null,
                null
        );
        System.out.println(check);
        boolean res = checkservice.Add(check);

        if(res) {
            response.getWriter().write(gson.toJson(R.ok().data("ok")));
        } else {
            response.getWriter().write(gson.toJson(R.error()));
        }

    }
}
